﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Fclient.Core;
using Flicker.Common;
using Windows.UI.Xaml;

namespace Fclient.ViewModel
{
    class MainPageViewModel : BindableBase
    {
        private string searchText = "weather";
        public string SearchText 
        {
            get
            {
                return searchText;
            }
            set
            {
                searchText = value;
                OnPropertyChanged("SearchText");

            }   
        }

        public ObservableCollection<PhotoItemViewModel> photos = new ObservableCollection<PhotoItemViewModel>();

        public ObservableCollection<PhotoItemViewModel> Photos
        {
            get
            {
                return photos;
            }
        }

        internal void FillPhoto()
        {
            photos.Clear();
            //photos = new List<PhotoItemViewModel>();

            new FlickerClient().GetPhotos(SearchText, (collecion) =>
            {
                
                foreach (var photo in collecion)
                {
                    photos.Add(new PhotoItemViewModel(photo)
                    {

                    });
                }

                OnPropertyChanged("Photos");
                
            });

            
        }
    }

    public class PhotoItemViewModel : BindableBase
    {
        public PhotoItemViewModel(FlickrNet.Photo photo)
        {
            //http://farm{farm-id}.staticflickr.com/{server-id}/{id}_{secret}_[mstzb].jpg

            ImageSourceMedium = String.Format("http://farm{0}.staticflickr.com/{1}/{2}_{3}_m.jpg",
                photo.Farm,
                photo.Server,
                photo.PhotoId,
                photo.Secret
                );

            ImageSourceBig = String.Format("http://farm{0}.staticflickr.com/{1}/{2}_{3}_b.jpg",
                photo.Farm,
                photo.Server,
                photo.PhotoId,
                photo.Secret
                );
        }

       
        private string imageSourceMedium;
        public string ImageSourceMedium
        {
            get { return imageSourceMedium; }
            set
            {
                imageSourceMedium = value;
                OnPropertyChanged("ImageSourceMedium");
            }
        }

        private string imageSourceBig;
        public string ImageSourceBig
        {
            get
            {
                return imageSourceBig;
            }
            set
            {
                imageSourceBig = value;
                OnPropertyChanged("ImageSourceBig");
            }
        }

        
    }
}
